package res

import "github.com/gin-gonic/gin"

type response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

var EmptyData = map[string]any{}

func (r response) ToJSON(c *gin.Context) {
	c.JSON(200, r)
}
func Ok(data any, msg string, c *gin.Context) {
	Er := getCode(SUCCESS)
	response{Er.Code, msg, data}.ToJSON(c)
}
func OkWithData(data any, c *gin.Context) {
	Er := getCode(SUCCESS)
	response{Er.Code, Er.Msg, data}.ToJSON(c)
}
func OkWithCode(ResultType string, c *gin.Context) {
	Er := getCode(ResultType)
	response{Er.Code, Er.Msg, EmptyData}.ToJSON(c)
}
func FailWithData(data any, c *gin.Context) {
	Er := getCode(SYS_ERR)
	response{Er.Code, Er.Msg, data}.ToJSON(c)
}
func FailWithCode(ErrType string, c *gin.Context) {
	Er := getCode(ErrType)
	response{Er.Code, Er.Msg, EmptyData}.ToJSON(c)
}
